package com.zut.yunxi.yunxi.controller;

import java.util.Arrays;
import java.util.Map;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.zut.yunxi.yunxi.entity.TProductEntity;
import com.zut.yunxi.yunxi.service.TProductService;
import com.atguigu.common.utils.PageUtils;
import com.atguigu.common.utils.R;



/**
 * 
 *
 * @author liqiqi
 * @email 523892377@qq.com
 * @date 2020-07-13 22:22:53
 */
@RestController
@RequestMapping("/yunxi/tproduct")
public class TProductController {
    @Autowired
    private TProductService tProductService;

    /**
     * 列表
     */
    @Cacheable(value = "tproductlist",key = "#params")
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = tProductService.queryPage(params);

        return R.ok().put("page", page);
    }
    @Cacheable(value = "tproductlistshop",key = "#params")
    @RequestMapping("/listshop")
    public R listshop(@RequestParam Map<String, Object> params){
        PageUtils page = tProductService.queryPageshop(params);

        return R.ok().put("page", page);
    }

    /**
     * 信息
     */
    @Cacheable(value = "tproductinfo",key = "#id")
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Integer id){
		TProductEntity tProduct = tProductService.getById(id);

        return R.ok().put("tProduct", tProduct);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody TProductEntity tProduct){
		tProductService.save(tProduct);

        return R.ok();
    }

    /**
     * 修改
     */
    @CachePut(value = "tproductinfo",key = "#tProduct")
    @RequestMapping("/update")
    public R update(@RequestBody TProductEntity tProduct){
		tProductService.updateById(tProduct);

        return R.ok();
    }

    /**
     * 删除
     */
    @CacheEvict(value = "tproductinfo",key = "#ids")
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] ids){
		tProductService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
